package createThread.cn.tedu.threaddemo.test2;

public class Main {
    public static int t1 = 0;
    public static int t2 = 0;
    public static int t3 = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 500; i++) {
                t1++;
            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 500; i++) {
                t2++;
            }
        });

        thread1.start();  // 一定要启动线程
        thread2.start();

        thread1.join();   // 等线程1结束
        thread2.join();   // 等线程2结束

        t3 = t1 + t2;     // 线程执行完后，读取两个变量求和
        String s1 = null;

        System.out.println(t3);
    }
}
